package com.example.viewpagertest2;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

/**
 * Created by Michael on 2015/1/13.
 */
public class Fragment3 extends Fragment {

    private ListView listView;

    private ArrayList<String> arrayList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.test_view3,container,false);

        listView = (ListView)view.findViewById(R.id.list_view);
        initDatas();

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,arrayList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getActivity(),"listView被点击了",Toast.LENGTH_LONG).show();
            }
        });

        return view;
    }

    private void initDatas(){

        arrayList = new ArrayList<String>();
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
        arrayList.add("dadsdfa");
    }
}
